package com.qding.park.manager.app.queue.handle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.common.core.cache.service.CacheServiceFacade;
import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.exceptions.IExceptionHandle;
import com.qding.park.common.core.exceptions.business.adapter.AdapterException;
import com.qding.park.common.core.exceptions.business.manager.adapterfactory.AdapterProxyCreateFail;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.facade.queue.service.BusinessFacade;
import com.qding.park.manager.pojo.TbMonthRent;
import com.qding.park.manager.pojo.TbReserve;
import com.qding.park.manager.pojo.queue.QueueMsg;

/**
  * @ClassName: ReserveDelayTimeoutHandle
  * @Description: 预定支付完成处理
  * @date 2016年10月20日 上午10:10:31
  */
@Component("reservePayedHandle")
public class ReservePayedHandle extends AbstractOrderHandle{

	
	/**
	 */
	@Autowired
	private BusinessFacade  businessFacade;
	
	
	@Override
	void actualHandle(QueueMsg msg) throws BaseException {
		JSONObject data = (JSONObject) msg.getData();
		TbReserve tbReserve=SerializeUtils.unSerialize(data.toJSONString(), TbReserve.class);
		businessFacade.reservePayedHandle(tbReserve);
	}


	@Override
	boolean failDiscardRollBacK(QueueMsg msg) {
		_log.error("预定支付完成回滚:" + msg);
		try {
			JSONObject data = (JSONObject) msg.getData();
			TbReserve tbReserve=SerializeUtils.unSerialize(data.toJSONString(), TbReserve.class);
			businessFacade.reservePayedIssuedFailRollBack(tbReserve);
			return true;
		} catch (Throwable e) {
			return false;
		}
	}
	
}
